package mythesis.gui.main.components;
import mythesis.gui.main.components.api.TileSource;
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.scene.text.*;
import javafx.scene.input.*;
import javafx.scene.image.*;

public class TilePanel extends CustomNode
{
    public var mode = 1;			// 1: Character, 2: Variable
    var dir          = "{{__DIR__}.substring(0, {__DIR__}.length()-20)}resource/";
    var icon         = "";
    var img:Image = new Image;
    
	var tileName = "";
	var tileDescription = "";
	
	// list of banned tiles
	public var banList:Boolean[] = 
	[
		false,
		false,
		false,
		false,
		false,
		
		false,
		false,
		false,
		false,
		false,
		
		false,
		false,
		false,
		false,
		false,
		
		false,
		false,
		false,
		false,
		false,
	];
	
	
	public var mouseClick = 0;

	var buttons = Group
	{
	    content:
	    [
			Text
	    	{
	    	    content:  "Character"
	    	    x: 24
	    	    y: 21
	    	    fill:  Color.BLACK
	    	    font      : Font.font("Courier New", FontWeight.BOLD, 15)
	    	}
	    	Text
	    	{
	    	    content:  "Character"
	    	    x: 25
	    	    y: 20
	    	    fill:  Color.WHITE
	    	    font      : Font.font("Courier New", FontWeight.BOLD, 15)
	    	}
			Text
	    	{
	    	    content:  "Variable"
	    	    x: 149
	    	    y: 21
	    	    fill:  Color.BLACK
	    	    font      : Font.font("Courier New", FontWeight.BOLD, 15)
	    	}
			Text
	    	{
	    	    content:  "Variable"
	    	    x: 150
	    	    y: 20
	    	    fill:  Color.WHITE
	    	    font      : Font.font("Courier New", FontWeight.BOLD, 15)
	    	}
	    	Rectangle
	    	{
	    		x: 0
	    		y: 0
	    		width: 130
	    		height: 25
				opacity   : 0.0
	    		onMouseClicked: function(e:MouseEvent):Void
				{
				    if (mode == 2)
				    {
				    	var x = tabs.content[1];
				    	delete tabs.content[1];
				    	insert x before tabs.content[0];
				    	mode = 1;
						{tabs.content[0] as Polyline}.fill = Color.web("#1C5337");
				    	{tabs.content[1] as Polyline}.fill = Color.web("#103283");
					}
				}
	    	}
	    	Rectangle
	    	{
	    		x: 130.1
	    		y: 0.0
	    		width: 130
	    		height: 25
	    		opacity   : 0.0
	    		onMouseClicked: function(e:MouseEvent):Void
				{
				    if (mode == 1)
				    {
					    var x = tabs.content[1];
					    delete tabs.content[1];
					    insert x before tabs.content[0];
				    	{tabs.content[0] as Polyline}.fill = Color.web("#091B46");
				    	{tabs.content[1] as Polyline}.fill = Color.web("#297C53");
					    mode = 2;
				    }
				}
	    	}
	    ]
	}

	var tabs = Group
    {
        content:
        [
        	Polyline	// Variable
        	{
        	    points:   [ 0.0, 25.0,
        	                130.0, 25.0,
        	                130.0, 0.0,
        	                260.0, 0.0, 
        	                260.0, 450.0,
        	                0.0, 450.0 ]
        	    fill        : Color.web("#1C5337");
        	    strokeWidth : 0
        	}
        	Polyline	// Character
        	{
        	    points:   [ 0.0, 0.0,
        	                130.0, 0.0,
        	                130.0, 25.0,
        	                260.0, 25.0, 
        	                260.0, 450.0,
        	                0.0, 450.0 ]
        	    fill        : Color.web("#103283");
        	    strokeWidth : 0
        	}
        	/*
       		Rectangle
       		{
       		    width     : 260; //260
       		    height    : 450; //450
       		    arcHeight : 5;
       		    arcWidth  : 5;
       		    fill      : Color.web("#297C53");
       		}
       		*/
        ]
    }
    
	var box = Group
	{
	    content:
	    [
	    	Rectangle
	    	{
	    	    x         : 10
	    	    y         : 40
	    	    width     : 240
	    	    height    : 395
	    	    arcWidth  : 10
	    	    arcHeight : 10
	    	    fill      : bind if (mode==1) Color.web("#0A0B29") else Color.web("#113121")
	    	}
	    ]
	}

	var tsCharacter = Group
	{
	    translateX: 20
	    translateY: 50
	    content:
	    [
	    	TileSource
	    	{
	    	    color: 1
	    		text: "Roll dice"
	    		ban: bind banList[0]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    		    				tileName = "Roll dice";
	    		    				tileDescription = "Rolls the dice.  The result is stored in the bonus variable allowedTurns.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoRollDice.png"
								       width  : 25
								       height : 25
			        	    		};
			        	    	}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[0] == false){ mouseClick = 1; }
	    		    			}
	    		
	    	}
	    	/*
	    	TileSource
	    	{
	    	    color: 1
	    		text: "Take shortcut"
	    		translateY: 17
	    		ban: bind banList[1]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Take shortcut";
	    						    tileDescription = "Take the shortcut when available.";
	    						   	img = Image
		        	    		    {
									   url    : "{dir}icoTakeShortcut.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[1] == false){ mouseClick = 2; }
	    		    			}
	    	}*/
	    	TileSource
	    	{
	    	    color: 1
	    		text: "Suggest..."
	    		translateY: 17
	    		ban: bind banList[2]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Suggest";
	    						    tileDescription = "Suggests a suspect (WORD), a weapon (WORD), plus the room you are inside.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoSuggest.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[2] == false){ mouseClick = 3; }
	    		    			}
	    	}
	    	TileSource
	    	{
	    	    color: 1
	    		text: "Accuse..."
	    		translateY: 34
	    		ban: bind banList[3]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Accuse";
	    						    tileDescription = "Accuses the name of the suspect, the weapon and the room, all of which are in WORD format.  Wrong accusations will prevent you from doing any other action except for disproving.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoAccuse.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[3] == false){ mouseClick = 4; }
	    		    			}
	    	}
	    	TileSource
	    	{
	    	    color: 1
	    		text: "Go to or approach..."
	    		translateY: 51
	    		ban: bind banList[4]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    		    				tileName = "Go to";
	    		    				tileDescription = "Goes to a specified room, given the number of turns from bonus variable allowedTurns.  Use Roll Dice before using this to give allowedTurns a value > 0.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoGoTo.png"
								       width  : 25
								       height : 25
			        	    		};
	    		    			}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[4] == false){ mouseClick = 5; }
	    		    			}
	    	}
	    	TileSource
	    	{
	    	    color: 1
	    		text: "Listen to suggestion"
	    		translateY: 68
	    		ban: bind banList[18]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    		    				tileName = "Listen...";
	    		    				tileDescription = "Hears when an enemy makes a suggestion.  Gives values to bonus variables to suggester, disproved and disprover, otherwhise they have default values blank and false.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoListen.png"
								       width  : 25
								       height : 25
			        	    		};
	    		    			}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[18] == false){ mouseClick = 19; }
	    		    			}
	    	}
	    	TileSource
	    	{
	    	    color: 1
	    		text: "Disprove suggestion..."
	    		translateY: 85
	    		ban: bind banList[19]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    		    				tileName = "Disprove...";
	    		    				tileDescription = "Indicates the order of disproval.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoDisprove.png"
								       width  : 25
								       height : 25
			        	    		};
	    		    			}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[19] == false){ mouseClick = 20; }
	    		    			}
	    	}
	    ]
	}
	
	var tsVariable = Group
	{
		translateX: 20
	    translateY: 50

	    content:
	    [
	    	TileSource
	    	{
	    	    color: 2
	    		text: "Note..."
	    		ban: bind banList[5]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Note";
	    						    tileDescription = "Records a note for future use.  May note a number, a word or a truth.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoNote.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[5] == false){ mouseClick = 6; }
	    		    			}
	    	}
	    	TileSource
	    	{
	    	    color: 2
	    		text: "Increase..."
	    		translateY: 17
	    		ban: bind banList[6]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    		    				tileName = "Increase";
	    		    				tileDescription = "Increase a number you have noted with another number or note.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoIncrease.png"
								       width  : 25
								       height : 25
			        	    		};
	    		    			}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[6] == false){ mouseClick = 7; }
	    		    			}
	    	}
	    	TileSource
	    	{
	    	    color: 2
	    		text: "Decrease..."
	    		translateY: 34
	    		ban: bind banList[7]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    		    				tileName = "Decrease";
	    		    				tileDescription = "Decreases a number you have noted with another number or note.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoDecrease.png"
								       width  : 25
								       height : 25
			        	    		};
	    		    			}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[7] == false){ mouseClick = 8; }
	    		    			}
	    	}
	    	TileSource
	    	{
	    	    color: 2
	    		text: "Multiply..."
	    		translateY: 51
	    		ban: bind banList[8]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Multiply";
	    						    tileDescription = "Multiplies a number you have noted with another number or note.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoMultiply.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[8] == false){ mouseClick = 9; }
	    		    			}
	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "Divide..."
	    		translateY: 68
	    		ban: bind banList[9]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Divide";
	    						    tileDescription = "Divides a number to the power of another or note.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoDivide.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[9] == false){ mouseClick = 10; }
	    		    			}
	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "Raise..."
	    		translateY: 85
	    		ban: bind banList[10]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Raise";
	    						    tileDescription = "Raises a number you have noted with another number or note.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoRaise.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[10] == false){ mouseClick = 11; }
	    		    			}
	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "Testify..."
	    		translateY: 102
	    		ban: bind banList[11]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Testify";
	    						    tileDescription = "Turns a truth note into true.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoTestify.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[11] == false){ mouseClick = 12; }
	    		    			}

	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "Falsify..."
	    		translateY: 119
	    		ban: bind banList[12]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Falsify";
	    						    tileDescription = "Turns a truth note into false.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoFalsify.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[12] == false){ mouseClick = 13; }
	    		    			}

	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "If condition..."
	    		translateY: 136
	    		ban: bind banList[13]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "If";
	    						    tileDescription = "States an if condition.  Executes statement(s) inside only when the condition is true.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoIf.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[13] == false){ mouseClick = 14; }
	    		    			}

	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "While condition..."
	    		translateY: 153
	    		ban: bind banList[14]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "While";
	    						    tileDescription = "States a while condition, limited to 100 iterations.  Similar to an if condition, statement(s) inside will be executed as long as the condition is true, up to 100 times.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoWhile.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[14] == false){ mouseClick = 15; }
	    		    			}

	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "Set..."
	    		translateY: 170
	    		ban: bind banList[15]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Set";
	    						    tileDescription = "Sets a note into an appropriate value.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoSet.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[15] == false){ mouseClick = 16; }
	    		    			}

	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "End Condition"
	    		translateY: 187
	    		ban: bind banList[16]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "End condition";
	    						    tileDescription = "Specifies the boundary of the If or While conditions.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoEnd.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[16] == false){ mouseClick = 17; }
	    		    			}

	    	}
			TileSource
	    	{
	    	    color: 2
	    		text: "Break Condition"
	    		translateY: 204
	    		ban: bind banList[17]
	    		onMouseEntered: function( e: MouseEvent): Void
	    						{
	    						    tileName = "Break condition";
	    						    tileDescription = "Breaks out of the While condition.";
	    		    				img = Image
		        	    		    {
									   url    : "{dir}icoBreak.png"
								       width  : 25
								       height : 25
			        	    		};
	    						}
	    		onMousePressed: function( e: MouseEvent): Void{
	    		    				if (banList[17] == false){ mouseClick = 18; }
	    		    			}

	    	}	
	    ]
	}

	var tileSources:Group[] = [tsCharacter, tsVariable];

	public var description = Group
	{
	    translateX: 20
	    translateY: 325
	    content:
	    [
	    	Rectangle
	    	{
	    	    width     : 220
	    	    height    : 100
	    	    arcWidth  : 10
	    	    arcHeight : 10
	    	    fill      : Color.web("#333333")
	    	}
        	ImageView
        	{
        	    x      : 5
        	    y      : 5
        	    image  : bind img;
        	    cache  : true
        	}
	    	Text
	    	{
	    	    x : 30
	    	    y : 25
	    	    content : bind tileName
	    	    font: Font.font("Courier New", FontWeight.BOLD, 20)
	    	    fill: Color.YELLOW
	    	}
	    	Text
	    	{
	    	    x : 10
	    	    y : 45
	    	    wrappingWidth: 200
	    	    content : bind tileDescription
	    	    font: Font.font("Verdana", FontWeight.REGULAR, 9)
	    	    fill: Color.WHITE
	    	}
	    	Line
	    	{
	    	    startX: 30
	    	    startY: 30
	    	    endX: 210
	    	    endY: 30
	    	    stroke: Color.YELLOW
	    	    strokeWidth: 2
	    	}
	    ]
	}

    public var group = Group
    {
        content: bind
        [
        	tabs,
        	buttons,
        	box,
        	description,
			tileSources[mode-1]        	
        ]
    }
    
    
    
    override public function create() : Node
    {
        return group
    }
}